package model;

// Representation of a resource
public class Resource extends Agent{

	public static final String Resource_Type_1 = "r1";
	public static final String Resource_Type_2 = "r2";
	public static final String Resource_Type_3 = "r3";
	
	String type;
	
	public Resource(Space2D universe_, Point location, String type) throws Exception {
		super(universe_, location);	
		this.type = type;
		
		Cell cell = this.universe.getCell(location);
		
		if (cell != null && cell.containsResource()){
			System.out.println("A resource is already in this location : "+ cell.getResource().toString() +" "+location.toString());
		} else {
			// Create the name			
			this.name = "Resource_"+type+"_"+universe.getCptResources();
			// Inc cptResources for future resources
			universe.incCptResources();
			
			//Add the resource into the cellsMap
			if (cell == null){
				cell = new Cell();
				universe.setCell(cell, location);
			}
			cell.setResource(this);
			System.out.println("Add the resource "+this.getName()+" at the location : "+location.toString());
		}
	}

	public String getType() {
		return type;
	}
	
	public static void testAddResources() throws Exception{
		Space2D space = new Space2D(50,50);
		Point p1 = new Point(10,10);
		Point p2 = new Point(11,10);
		Point p3 = new Point(12,10);
		Resource r1 = new Resource(space,p1, "leaf");
		Resource r2 = new Resource(space,p1, "leaf");
		Resource r3 = new Resource(space,p2, "deadant");
		Resource r4 = new Resource(space,p2, "leaf");
		Resource r5 = new Resource(space,p1, "deadant");
		Resource r6 = new Resource(space,p3, "strawberry");
	}
	
	public static void main(String args[]) throws Exception{
		testAddResources();
	}
	
}
